﻿<common:LayoutAwarePage
    x:Class="Looptribe.Moodlin8.View.UploadsPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:common="using:Looptribe.Moodlin8.Common" xmlns:local="using:Looptribe.Moodlin8.View"
    DataContext="{Binding Uploads, Source={StaticResource Locator}}"
    mc:Ignorable="d">
    
    <Page.Resources>
        <Style x:Key="FileLinkTemplate" TargetType="Button">
            <Setter Property="Background" Value="{StaticResource ButtonBackgroundThemeBrush}"/>
            <Setter Property="Foreground" Value="{StaticResource ButtonForegroundThemeBrush}"/>
            <Setter Property="BorderBrush" Value="{StaticResource ButtonBorderThemeBrush}"/>
            <Setter Property="BorderThickness" Value="{StaticResource ButtonBorderThemeThickness}"/>
            <Setter Property="Padding" Value="12,4,12,4"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Margin="2" Width="300" Height="40">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="40" Height="40">
                                <Image Stretch="UniformToFill">
                                    <Image.Source>
                                        <Binding Path="FileType" Converter="{StaticResource fileTypeConverter}" />
                                    </Image.Source>
                                </Image>
                            </Border>
                            <StackPanel Grid.Column="1" Margin="10,0,0,0">
                                <TextBlock Text="{Binding Name}" Style="{StaticResource ItemTextStyle}" TextWrapping="NoWrap" TextTrimming="None"/>
                            </StackPanel>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <DataTemplate x:Key="UploadsTemplate">
            <Button Style="{StaticResource FileLinkTemplate}" Click="OpenUploadClick"></Button>
        </DataTemplate>

        <Style x:Key="MoodleUploadAppButtonStyle" TargetType="Button" BasedOn="{StaticResource MoodleAppBarButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="UploadAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Upload"/>
            <Setter Property="Content" Value="&#xE11C;"/>
        </Style>
    </Page.Resources>

    <Page.BottomAppBar>
        <AppBar x:Name="BottomAppBar1" Padding="10,0,10,0" AutomationProperties.Name="Bottom App Bar" Background="{StaticResource MoodleOrangeColor}" Foreground="White">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <!--<StackPanel x:Name="LeftPanel" Orientation="Horizontal" Grid.Column="0" HorizontalAlignment="Left">
                    <Button x:Name="Pin" Style="{StaticResource MoodlePinAppBarButtonStyle}" AutomationProperties.Name="{Binding PinButtonText}" Content="{Binding PinButtonIcon}" Tag="Pin to start" Command="{Binding PinToStartCommand}" />
                </StackPanel>-->
                <StackPanel x:Name="RightPanel" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right">
                    <Button x:Name="Upload" Style="{StaticResource MoodleUploadAppButtonStyle}" Tag="Upload" Command="{Binding UploadFileCommand}"/>
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.BottomAppBar>

    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ProgressBar IsIndeterminate="True" Grid.Row="1" Visibility="{Binding IsLoading,Converter={StaticResource BooleanToVisibilityConverter}}" />

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <StackPanel Orientation="Horizontal" Grid.Column="1">
                <TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" IsHitTestVisible="false" Style="{StaticResource MoodleAppTitleSyle}"/>
                <local:NavPopup Text="Uploads" />
            </StackPanel>
        </Grid>

        <!--<ListView x:Name="hubNextAssignmentsListview" Grid.Row="1" Margin="0,20,0,0" Width="330" Height="Auto" ItemsSource="{Binding Assignments}" ItemTemplate="{StaticResource NextAssignmentsTemplate}" SelectionMode="None" IsSwipeEnabled="False"/>-->
        <ListView Padding="116,0,116,46" Grid.Row="1" Margin="0,20,0,0" ItemsSource="{Binding Uploads}" ItemTemplate="{StaticResource UploadsTemplate}" SelectionMode="None">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapGrid Orientation="Vertical" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
        </ListView>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>